<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%@ include file="/WEB-INF/component/commonTagLib.jsp" %>
<!DOCTYPE html>
<html>
<head>
<title>预约规则设置</title>
 <%@ include file="/WEB-INF/component/commonCSS.jsp" %>
<!--[if lt IE 9]>
        <script src="lib/js/html5shiv.min.js"></script>
        <script src="lib/js/respond.min.js"></script>
    <![endif]-->
    <style type="text/css">
    	div.box-body {
    		margin-top:7px;
    	}
    </style>
    
</head>
<body class="skin-blue-light sidebar-mini fixed skin-blue-light-frame">
	<section class="content-header">
		<h1>预约规则设置</h1>
		<ol class="breadcrumb">
			<li><a href="${ctx}/home.jsp"><i class="fa fa-home"></i>首页</a></li>
			   <li class="active">药品招标管理</li>
            <li class="active">预约管理</li>
		</ol>
	</section>

	<section class="content">
		<div class=" box box-success">
			<div class="box-body" >
			 <div style="position: absolute;bottom:45px;right:10px;">
             <img src="/medstgmini/lib/img/centersubscribe.png">
             </div> 
				<form role="form" class="form-horizontal" id="FormSubmit" action="${ctx }/bidSubscribe/saveBidSubscribe.html" method="post">
					<div style="margin-left:60px;">
					   <label>项目名称：</label>
					   <span>${projName}</span>
					   <c:if test="${defalutProjId != null}">
					    <input type="hidden" style="width: 220px;" id="defalutProjId" name="defalutProjId" value="${defalutProjId}" >
					   </c:if>
					    <c:if test="${projId != null}">
					     <input type="hidden" style="width: 220px;" id="projId" name="projId" value="${projId}" >
					    </c:if>
					   <br></br>
					   <label  for="searchrecpAddr">预约日期：</label>
                       <input style="width: 100px;" placeholder="开始日期" name="subStartDate" id="subStartDate" 
                       type="text"   data-date-fmt="yyyy-MM-dd" placeholder="yyyy-MM-dd"  onFocus="WdatePicker({maxDate:'#F{$dp.$D(\'subEndDate\')}'})">
                   	   <label>-</label>
                       <input  style="width: 100px;" placeholder="结束日期" name="subEndDate" id="subEndDate"
                        type="text"  data-date-fmt="yyyy-MM-dd" placeholder="yyyy-MM-dd" onFocus="WdatePicker({minDate:'#F{$dp.$D(\'subStartDate\')}'})">
                       <br></br>
					   <label  for="txtDrugName" style="margin-left:-24px;">是否包含周末：</label>
					   <input type="hidden" id="includeWeekend" name="includeWeekend" value="0">
                       <img id="redioSelect" src="${ctx }/lib/img/rule/n.png" style="vertical-align: middle;"><span style="margin-left: 4px;">是</span>
                   	   <img  id="redioSelect2" src="${ctx }/lib/img/rule/y.png" style="margin-left: 25px;"><span style="margin-left: 4px;">否</span>
                   	   <br></br>
                   	   
                   	   <label  for="txtDrugName" style="margin-left:24px;">上午：</label>
					   <input style="width: 100px;" placeholder="开始时间" name="processStartTimeOne" id="processStartTimeOne" type="text"  value="" readonly="readonly" data-provide="datepicker" data-date-fmt="HH:mm" placeholder="yyyy-mm-dd">
                       <label>-</label> 
                       <input  style="width: 100px;" placeholder="结束时间" name="processEndTimeOne" id="processEndTimeOne" type="text"  value=""readonly="readonly" data-provide="datepicker" data-date-fmt="HH:mm" placeholder="yyyy-mm-dd">
                       <label>每</label> 
                        <select id="processUnitOne" name="processUnitOne" style="width:100px">
                       		<option value="10">10分钟</option>
                       		<option value="15">15分钟</option>
                       		<option value="30">30分钟</option>
                       </select>
                       <label>接待</label> 
                       <input type="text" maxlength="5" id="personCountOne" name="personCountOne" style="width: 40px;">
                       <label>人</label>
                       <label><span style="color:red">请设定整点时间或30分钟</span></label>
                       <!-- <div><font style="margin-left: 65px;" color="red">请设定整点时间或30分钟</font></div>-->
                       <br></br>
                        <label  for="txtDrugName" style="margin-left:24px;">下午：</label>
					   <input style="width: 100px;" placeholder="开始时间" name="processStartTimeTwo" id="processStartTimeTwo" type="text"  value=""  readonly="readonly"data-provide="datepicker" data-date-fmt="HH:mm" placeholder="yyyy-mm-dd">
                       <label>-</label>
                       <input  style="width: 100px;" placeholder="结束时间" name="processEndTimeTwo" id="processEndTimeTwo" type="text"  value="" readonly="readonly" data-provide="datepicker" data-date-fmt="HH:mm" placeholder="yyyy-mm-dd">
                       <label  for="txtDrugName" >每</label>
                       <select id="processUnitTwo" name="processUnitTwo" style="width:100px">
                       		<option value="10">10分钟</option>
                       		<option value="15">15分钟</option>
                       		<option value="30">30分钟</option>
                       </select>
                        <label  for="txtDrugName">接待</label>
                       <input type="text" maxlength="5" id="personCountTwo" name="personCountTwo" style="width: 40px;">
                       <label>人</label>
                       <label><span style="color:red">请设定整点时间或30分钟</span></label>
                       <!--<div><font style="margin-left: 65px;" color="red">请设定整点时间或30分钟</font></div>-->
                       <br></br>
                       <label  for="txtDrugName" style="margin-left:-24px;">现场确认地址：</label>
                       <input  type="text" maxlength="50" id="centerAddress" name="centerAddress" value="${address}" style="width: 220px;">
                       <br></br>
                       <div style="margin-left:67px;">
                       <input type="hidden" id=isEnable name="isEnable" value="0">
                       <img id="statusSelect" src="${ctx }/lib/img/rule/n.png" style="vertical-align: middle;"><span style="margin-left: 4px;">立即开启</span>
				       </div>
				</div>

				 
                </form>
			</div>
			<div class="box-footer text-center">
                    <button type="button" onclick="save(1);" class="btn btn-success btn-sm">确&nbsp;定</button>
                    <c:if test="${defalutProjId == null}">
                    	<button type="button" onclick="back();" class="btn btn-danger btn-sm">返&nbsp;回</button>
                    </c:if>
                     <c:if test="${defalutProjId != null}">
                    </c:if>
                </div>
		</div>
		<div id='coverdiv' style="Opacity:0.8;  position:fixed; left:0px; top:0px;width:100%;height:100%;"> </div>
        <div id='mydiv' style="border:0px solid #666666 ; padding:50px;text-align:center; position:absolute;background-image: url('${ctx }/lib/img/loading.gif'); background-repeat: no-repeat;">
</div>
	</section>
   <%@ include file="/WEB-INF/component/commonJS.jsp" %>
	<script type="text/javascript">
	$(function(){
		var projstartTime = "${startTime}";
		var projendTime = "${endTime}";
		var defaultProjId = "${defalutProjId}";
		var projDate = new Date();
   	    var projday1 = projDate.getDate();                 
         var projmonth1 = projDate.getMonth() + 1;             
         var projyear1 = projDate.getFullYear();
         if(projmonth1 < 10){
        	 projmonth1 = "0" +projmonth1;
         }
         if(projday1 < 10){
        	 projday1 = "0" + projday1 ;
         }
         var projfullDate = projyear1 + "-" + projmonth1 + "-" + projday1;
		if("undefined" == projstartTime || "" == projstartTime || null == projstartTime){
			top.$.alert("该项目招标时间还未开始，不能进行预约！", "warn");
			if("undefined" != defaultProjId && "" != defaultProjId && null != defaultProjId){
				setTimeout("backById()",2000);
			}else{
				setTimeout("back()",2000);
			}
			
		}else if(projendTime < projfullDate){
			top.$.alert("该项目招标时间已结束，已不能进行预约！", "warn");
			if("undefined" != defaultProjId && "" != defaultProjId && null != defaultProjId){
				setTimeout("backById()",2000);
			}else{
				setTimeout("back()",2000);
			}
		}
	});
	var cover =mydiv= null;
	window.onload = function() {
	  cover=document.getElementById('coverdiv');
	  cover.style.width = Math.max(document.documentElement.scrollWidth, document.documentElement.clientWidth) + "px";
	  cover.style.height = Math.max(document.documentElement.scrollHeight, document.documentElement.clientHeight) + "px"
	  cover.style.display = "none";
	 
	  mydiv = document.getElementById('mydiv');
	  with (mydiv){
	    style.width = document.documentElement.scrollHeight/2+"px";
	    style.height = document.documentElement.scrollHeight/2+"px";
	    style.left = (document.documentElement.scrollWidth - mydiv.offsetWidth)/2+"px";
	    style.top = (document.documentElement.scrollHeight - mydiv.offsetHeight)/2+"px";
	 
	    style.display = "none";
	  }
	};
	
		$("#redioSelect").click(function(){
			$("#redioSelect").attr("src","${ctx }/lib/img/rule/y.png");
			$("#redioSelect2").attr("src","${ctx }/lib/img/rule/n.png");
			$("#includeWeekend").val("1");
		})
		$("#redioSelect2").click(function(){
			$("#redioSelect2").attr("src","${ctx }/lib/img/rule/y.png");
			$("#redioSelect").attr("src","${ctx }/lib/img/rule/n.png");
			$("#includeWeekend").val("0");
		})
		
		$("#statusSelect").click(function(){
			if("1" == $("#isEnable").val()){
				$("#statusSelect").attr("src","${ctx }/lib/img/rule/n.png");
				$("#isEnable").val("0");
			}else{
				$("#statusSelect").attr("src","${ctx }/lib/img/rule/y.png");
				$("#isEnable").val("1");
			}
			
			
		})
		function save(obj){
			if(!validate()){
	    		return;
	    	}
	    	  $.HN.message.confirm('确定要保存吗？', '', '').on(function (e) {
	              if (e) {
	            	  mydiv.style.display =cover.style.display = '';
	            	  $("#FormSubmit").ajaxSubmit({
	            		  dataType : "json",
	            		  success: function(result,statusText) {
	                		if(result.success){
	                			var isEnable = result.conditions.isEnable;
	                			var bidSubscribeId = result.conditions.bidSubscribeId;
	                			var defalutProjId = result.conditions.defalutProjId;
	                			if(0 == Number(isEnable) && "" != defalutProjId){
	                				$.HN.message.alert('保存成功！', '提示信息', 'success');
	                				window.location.href="${ctx}/bidSubscribe/toSubscribeEditJsp.html?bidSubscribeId="+bidSubscribeId;
	                			}
	                			if(1 == Number(isEnable) && "" != defalutProjId){
	                				    $.HN.message.alert('保存成功！', '提示信息', 'success');
	                					window.location.href="${ctx}/bidSubscribe/toCompRecordJsp.html?defalutProjId="+defalutProjId+"&bidSubscribeId="+bidSubscribeId;
	                			}
	                			if("" == defalutProjId || null == defalutProjId ){
	                					$.HN.message.alert('保存成功！', '提示信息', 'success');
	    	        	     			window.location.href="${ctx}/bidSubscribe/toSetSubProjListJsp.html";
	                				}
	                			mydiv.style.display =cover.style.display = 'none';
	                		}else{
	                			$.HN.message.alert('保存失败！', '提示信息', 'success');
	                		}
	            		  }
	      	   	  });
	            	  }
	    	  });
		}
		
		function back(){
			window.location.href="${ctx}/bidSubscribe/toSetSubProjListJsp.html";
		}
		function backById(){
			window.location.href="${ctx}/bidProject/toChangeBidProjectList.html";
		}
		function validate(){
			var startTime = "${startTime}";
			var endTime = "${endTime}";
			
			var myDate = new Date();
       	    var day1 = myDate.getDate();                 
	         var month1 = myDate.getMonth() + 1;             
	         var year1 = myDate.getFullYear();
	         if(month1 < 10){
	        	 month1 = "0" + month1;
	         }
	         if(day1 < 10){
	        	 day1 = "0" + day1 ;
	         }
	         var fullDate = year1 + "-" + month1 + "-" + day1;
			var subStartDate = $.trim($("#subStartDate").val());
			
			if (subStartDate == null || subStartDate == "") {
				$.alert("请设置预约开始日期！","warn");
				return false;
			}else {
				if(subStartDate < fullDate){
					$.alert("您设置的预约开始日期已过期！应大于"+startTime+"！", "warn");
					return false;
				}
			}
			$("#subStartDate").val(subStartDate);
			
			var subEndDate = $.trim($("#subEndDate").val());
			if (subEndDate == null || subEndDate == "") {
				$.alert("请设置预约结束日期！", "warn");
				return false;
			}else if(subEndDate > endTime){
				$.alert("设置的预约结束日期小于"+endTime+"！",  "warn");
				return false;
			}
			$("#subEndDate").val(subEndDate);
			
			if($("#subStartDate").val() > $("#subEndDate").val()){
				$.alert("设置的预约开始日期错误！开始日期应比结束日期小",  "warn");
				return false;
			}
			
			var processStartTimeOne = $.trim($("#processStartTimeOne").val());
			if (processStartTimeOne == null || processStartTimeOne == "") {
				$.alert("请设置上午的开始时间！", "warn");
				return false;
			}else{
				var arrt = new Array();
				arrt = processStartTimeOne.split(':')
				if(arrt[1] != "30" && arrt[1] != "00"){
					$.alert("请设置上午的开始时间应为整点或30分钟！","warn");
					processStartTimeOne = arrt[0]+":"+30
					$("#processStartTimeOne").val(processStartTimeOne)
					return false;
				}
				if(processStartTimeOne < "06:00"){
					$.alert("设置上午的开始时间应大于6:00！",  "warn");
					return false;
				}
			}
				
			$("#processStartTimeOne").val(processStartTimeOne)
			
			var processEndTimeOne = $.trim($("#processEndTimeOne").val());
			if (processEndTimeOne == null || processEndTimeOne == "") {
				$.alert("请设置上午的结束时间！", "warn");
				return false;
			}else{ 
				var arrt = new Array();
				arrt = processEndTimeOne.split(':')
				if(arrt[1] != "30" && arrt[1] != "00"){
					$.alert("请设置上午的结束时间应为整点或30分钟！","warn");
					processEndTimeOne = arrt[0]+":"+30
					$("#processEndTimeOne").val(processEndTimeOne)
					return false;
				}
				if(processEndTimeOne > "12:00"){
				$.alert("设置上午的结束时间应小于12:00！",  "warn");
				return false;
			  }
			}	
			$("#processEndTimeOne").val(processEndTimeOne)
			
			if($("#processStartTimeOne").val() >= $("#processEndTimeOne").val()){
				$.alert("设置的上午的开始时间错误！开始时间应比结束时间小", "warn");
				return false;
			}
			
			var personCountOne = $.trim($("#personCountOne").val());
			if (personCountOne == null || personCountOne == "") {
				$.alert("请设置上午的预约人数！", "warn");
				return false;
			} 
			$("#personCountOne").val(personCountOne);
			
			var processStartTimeTwo = $.trim($("#processStartTimeTwo").val());
			if (processStartTimeTwo == null || processStartTimeTwo == "") {
				$.alert("请设置下午的开始时间！", "warn");
				return false;
			} else{
				var arrt = new Array();
				arrt = processStartTimeTwo.split(':')
				if(arrt[1] != "30" && arrt[1] != "00"){
					$.alert("请设置下午的开始时间应为整点或30分钟！","warn");
					processStartTimeTwo = arrt[0]+":"+30
					$("#processStartTimeTwo").val(processStartTimeTwo)
					return false;
				}
				
				if(processStartTimeTwo < "13:00"){
				$.alert("设置下午的开始时间应大于13:00！", "warn");
				return false;
			  }
			}
			$("#processStartTimeTwo").val(processStartTimeTwo)
			
			var processEndTimeTwo = $.trim($("#processEndTimeTwo").val());
			if (processEndTimeTwo == null || processEndTimeTwo == "") {
				$.alert("请设置下午的结束时间！", "warn");
				return false;
			}else {
				var arrt = new Array();
				arrt = processEndTimeTwo.split(':')
				if(arrt[1] != "30" && arrt[1] != "00"){
					$.alert("请设置下午的结束时间应为整点或30分钟！","warn");
					processEndTimeTwo = arrt[0]+":"+30
					$("#processEndTimeTwo").val(processEndTimeTwo)
					return false;
				}
				if(processEndTimeTwo > "18:00"){
				$.alert("设置下午的结束时间应小于18:00！", "warn");
				return false;
			  }
			}
			$("#processEndTimeTwo").val(processEndTimeTwo)
			
			if($("#processStartTimeTwo").val() >= $("#processEndTimeTwo").val()){
				$.alert("设置的下午的开始时间错误！开始时间应比结束时间小","warn");
				return false;
			}
			
			var personCountTwo = $.trim($("#personCountTwo").val());
			if (personCountTwo == null || personCountTwo == "") {
				$.alert("请设置下午的预约人数！",  "warn");
				return false;
			} 
			$("#personCountTwo").val(personCountTwo);

			var centerAddress = $.trim($("#centerAddress").val());
			if (centerAddress == null || centerAddress == "") {
				$.alert("请设置现场确认地址！","warn");
				return false;
			} 
			$("#centerAddress").val(centerAddress);
			return true;
		}
	</script>
</body>
</html>









